pp108 : rename Method (Tree)

rename Method (Tree)


This method makes the selected item editable so that the description of the selected tree item can be changed.

Syntax

selectedNode.rename()

Return Value

No return value.

Remarks

This method should be called only on a selected node.
Once the method is invoked, a textbox appears in the place of the tree node description, where the users can type-in the new description. Once the description is typed, it can be set to the tree by the following actions.

  1. Click the <enter> key.
  2. Select some other node.
  3. Use tab to switch to the next node.

However, the data of the item for which the change is made will always point to the old description. It is the responsibility of the users to manually change the treeData of the item.

Calling the rename method will also invoke the function associated with the onchange property of the tree item. For this to happen, the updateAllowed property need not be set on the tree item.

Example

The following example shows how the method is used.

//Function call when contextmenu is activated on a tree node to rename it
function oncontextRenameItem()
{
    //Get the context item
    var item = event.activeElement.getTreeItem();
    //Check if it is the selected item
    if (item == sampletree.getSelectedItem())
    {
        //Yes, so click rename
        item.rename();
    }
    else
    {
        //Alert error - Depends on whether there is a selected item and that is equal to the contexted one
        if (sampletree.getSelectedItem() == null) application.notify("No item selected !");
        else application.notify("Item selected is not the same as the contexted item !");
    }
}

See Also

tree, updateAllowed, onchange